package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IEmailRuleConfigurationService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.EmailRuleConfigurationCreateValidate;
import com.mdd.admin.validate.EmailRuleConfigurationUpdateValidate;
import com.mdd.admin.validate.EmailRuleConfigurationSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.EmailRuleConfigurationListedVo;
import com.mdd.admin.vo.EmailRuleConfigurationDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/ruleconfiguration")
@Api(tags = "规则邮箱配置管理")
public class EmailRuleConfigurationController {

    @Resource
    IEmailRuleConfigurationService iEmailRuleConfigurationService;

    @GetMapping("/list")
    @ApiOperation(value="规则邮箱配置列表")
    public AjaxResult<PageResult<EmailRuleConfigurationListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated EmailRuleConfigurationSearchValidate searchValidate) {
        PageResult<EmailRuleConfigurationListedVo> list = iEmailRuleConfigurationService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="规则邮箱配置详情")
    public AjaxResult<EmailRuleConfigurationDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        EmailRuleConfigurationDetailVo detail = iEmailRuleConfigurationService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "规则邮箱配置新增")
    @PostMapping("/add")
    @ApiOperation(value="规则邮箱配置新增")
    public AjaxResult<Object> add(@Validated @RequestBody EmailRuleConfigurationCreateValidate createValidate) {
        iEmailRuleConfigurationService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "规则邮箱配置编辑")
    @PostMapping("/edit")
    @ApiOperation(value="规则邮箱配置编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody EmailRuleConfigurationUpdateValidate updateValidate) {
        iEmailRuleConfigurationService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "规则邮箱配置删除")
    @PostMapping("/del")
    @ApiOperation(value="规则邮箱配置删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iEmailRuleConfigurationService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
